package portal.web.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import javax.naming.Context;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import portal.facade.PortalComprasFacadeStateful;
import portal.web.businessDelegate.PortalComprasDelegate;
import portal.vo.ConfigVO;



@SuppressWarnings("serial")
public class ConfigSaveServlet extends HttpServlet {
	
	private static Logger logger = Logger.getLogger(AutenticarUsuarioServlet.class);	
	
	final String appName = "PortalDeComprasEAR";
    final String moduleName = "PortalDeComprasSrv";
    final String sessionBeanNameStateful = "PortalComprasFacadeStatefulBean";
    final String viewClassNameStateful = PortalComprasFacadeStateful.class.getName();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		processRequest(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		processRequest(req, resp);
	}

	private void processRequest(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		
		//logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>ConfigSaveServlet<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
		List<ConfigVO> configs = new ArrayList<ConfigVO>();
		
		
		Enumeration<String> paramNames = req.getParameterNames();

		while(paramNames.hasMoreElements()) {
			String paramName = paramNames.nextElement();
			String paramValue =  req.getParameter(paramName);
			
			ConfigVO vo = new ConfigVO();
			vo.setId(Long.parseLong(paramName));
			vo.setConfigurationValue(paramValue);
			
			configs.add(vo);
			
			
		}
		
		
		
		PortalComprasDelegate.getInstance().setListaConfiguraciones(configs);
		
		req.getRequestDispatcher("/ConfigsServlet").forward(req, resp);
		
		
	}
		
		
}
	